Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing /
Chapter 3 - Page Formatting and Dialog Box Customization / Using Printing-Related Collection Objects


Using a Collection to Implement the Print One Copy Menu Item

To implement the Print One Copy menu item, you must change items in the job collection. You must ensure that only one copy will be printed, that all pages will be printed, and that the output will actually go to a printer and not to a print file. After the copy has been printed, you must set the contents of the collection items back to their original values so that the user's settings are preserved.

Listing 3-4 shows how to set the values of the gxCopiesTag, gxPageRangeInfo, and gxFileDestinationTag items so that only one copy of all pages is printed and it is sent to the printer. It also shows how to restore the original values for these collection items after the print operation has been completed.

Listing 3-4 Modifying the job collection to implement the Print One Copy menu item

OSErr MyPrintOneCopy(MyDocumentPtr whichDocument)
{
   OSErr                   err;
   Collection              jobCollection;
   gxCopiesInfo            copiesInfo;
   gxFileDestinationInfo   destInfo;
   gxPageRangeInfo         pageRangeInfo;
   Ptr                     oldCopiesInfo = nil; 
   Ptr                     oldPageRangeInfo = nil; 
   Ptr                     oldDestInfo = nil;
   long                    oldCopiesSize; 
   long                    oldPageRangeInfoSize; 
   long                    oldDestInfoSize;


   /* Get the job collection and set it up to print one copy */
   jobCollection = GXGetJobCollection(whichDocument->documentJob);

   /* Set number of copies to 1 */
   copiesInfo.copies = 1;
   err = MyReplaceCollectionItem(&copiesInfo,
                           sizeof(gxCopiesInfo),
                           gxCopiesTag, gxPrintingTagID,
                           jobCollection, &oldCopiesInfo,
                           &oldCopiesSize);
   nrequire(err, ReplaceCopies_error);

   /* Set page range to "all". */
   pageRangeInfo.simpleRange.optionChosen = gxDefaultPageRange;
   pageRangeInfo.minFromPage = 1;
   pageRangeInfo.simpleRange.fromPage = 1;
   pageRangeInfo.maxToPage = whichDocument->numPages;
   pageRangeInfo.simpleRange.toPage = whichDocument->numPages;
   pageRangeInfo.simpleRange.printAll = true;
   err = MyReplaceCollectionItem(&pageRangeInfo,
                           sizeof(gxPageRangeInfo),
                           gxPageRangeTag, gxPrintingTagID,
                           jobCollection, &oldPageRangeInfo,
                           &oldPageRangeInfoSize);
   nrequire(err, ReplacePageRange_error);

   /* Set destination to "printer". */
   destInfo.toFile = false;
   err = MyReplaceCollectionItem(&destInfo,
                           sizeof(gxFileDestinationInfo),
                           gxFileDestinationTag, gxPrintingTagID,
                           jobCollection, &oldDestInfo,
                           &oldDestInfoSize);
   nrequire(err, ReplaceDestination_error);

   /* Print one copy of the document. (not shown here) */
   err = MyPrintDocument(whichDocument);

   /* 
      Restore original number of copies, page range, and output
      destination in case it needs to be reused. 
   */
ReplaceCopies_error:
   MyReplaceCollectionItem(oldCopiesInfo, oldCopiesSize,
                     gxCopiesTag, gxPrintingTagID,
                     jobCollection, nil, nil);
ReplacePageRange_error:
   MyReplaceCollectionItem(oldPageRangeInfo, oldPageRangeInfoSize,
                     gxPageRangeTag, gxPrintingTagID,
                     jobCollection, nil, nil);
ReplaceDestination_error:
   MyReplaceCollectionItem(oldDestInfo, oldDestInfoSize,
                     gxFileDestinationTag, gxPrintingTagID,
                     jobCollection, nil, nil);

   /* Dispose of pointers created by MyReplaceCollectionItem */
   if (oldCopiesInfo)
      DisposePtr(oldCopiesInfo);
   if (oldPageRangeInfo)
      DisposePtr(oldPageRangeInfo);
   if (oldDestInfo)
      DisposePtr(oldDestInfo);

   return err;
}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help